package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class SpliceAdapter extends StkProviderMultiAdapter<String> {

    public SpliceAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(62));
        addItemProvider(new SplitProvider());
    }

    private int pos = 0;
    private int current=0;

    public void setCurrent(int current){
        this.current=current;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    private class SplitProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_video_splice;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String path) {
            baseViewHolder.getView(R.id.ivVideoSpliceItemExchange).setVisibility(View.VISIBLE);
            Glide.with(getContext()).load(path)
                    .into((ImageView) baseViewHolder.getView(R.id.ivVideoSpliceItemImg));
            if (pos == baseViewHolder.getAdapterPosition()) {
//                baseViewHolder.getView(R.id.ivVideoSpliceItemExchange).setVisibility(View.GONE);
            }
            if (current==baseViewHolder.getBindingAdapterPosition()){
                baseViewHolder.setVisible(R.id.ivVideoSpliceItemSel,true);
            }else{
                baseViewHolder.setVisible(R.id.ivVideoSpliceItemSel,false);
            }
        }
    }

}
